<?php
class content_tag {
	private $db;
	private $company_db;
	private $designer_db;
	private $buy_product_db;
	public function __construct() {
		$this->db = pc_base::load_model('content_model');
		$this->position = pc_base::load_model('position_data_model');
	}
	/**
	 * 初始化模型
	 * @param $catid
	 */
	public function set_modelid($catid) {
		$siteids = getcache('category_content','commons');
		if(!$siteids[$catid]) return false;
		$siteid = $siteids[$catid];
		$this->category = getcache('category_content_'.$siteid,'commons');
		$this->modelid = $this->category[$catid]['modelid'];
		$this->db->set_model($this->modelid);
		$this->tablename = $this->db->table_name;
		if(empty($this->category)) {
			return false;
		} else {
			return true;
		}
	}
	/**
	 * 分页统计
	 * @param $data
	 */
	public function count($data) {
		if($data['action'] == 'lists') {
			$catid = intval($data['catid']);
			if(!$this->set_modelid($catid)) return false;
			if(isset($data['where'])) {
				$sql = $data['where'];
			} else {
				if($this->category[$catid]['child']) {
					$catids_str = $this->category[$catid]['arrchildid'];
					$pos = strpos($catids_str,',')+1;
					$catids_str = substr($catids_str, $pos);
					$sql = "status=99 AND catid IN ($catids_str)";
				} else {
					$sql = "status=99 AND catid='$catid'";
				}
			}
			return $this->db->count($sql);
		}
	}
	
	/**
	 * 列表页标签
	 * @param $data
	 */
	public function lists($data) {
		
		$catid = intval($data['catid']);
		if(!$this->set_modelid($catid)) return false;
		
		//查找自己发的东西的时候用
		if(isset($data['username'])){
			$data['where'] = 'username=\''.$data['username'].'\'';
		}
		//手动设定取数据的条数
		if($data['limits']){
			$data['limit'] = $data['limits'];
		}
		if(isset($data['where'])) {
			$sql = $data['where'];
		} else {
			$thumb = intval($data['thumb']) ? " AND thumb != ''" : '';
			if($this->category[$catid]['child']) {
				$catids_str = $this->category[$catid]['arrchildid'];
				$pos = strpos($catids_str,',')+1;
				$catids_str = substr($catids_str, $pos);
				$sql = "status=99 AND catid IN ($catids_str)".$thumb;
			} else {
				$sql = "status=99 AND catid='$catid'".$thumb;
			}
		}
		
		$order = $data['order'];
	//	$sql = $sql.' l'
	//echo $sql;
	
		$return = $this->db->select($sql, '*', $data['limit'], $order, '', 'id');
		///echo '<pre>';
	//	print_r($return);		
		//$data['moreinfo'] = 1; //这句自已加的
		
		//调用副表的数据
		if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) {
			
			$ids = array();
			foreach ($return as $v) {
				if (isset($v['id']) && !empty($v['id'])) {
					$ids[] = $v['id'];
				} else {
					continue;
				}
			}
			
			$idss = $ids;
			if (!empty($ids)) {
				$this->db->table_name = $this->db->table_name.'_data';
				$ids = implode('\',\'', $ids);
				$r = $this->db->select("`id` IN ('$ids') ", '*', '', '', '', 'id');
			
				if (!empty($r)) {
					foreach ($r as $k=>$v) {
					//print_r($return[$k]);
						if (isset($return[$k])) $return[$k] = array_merge($v, $return[$k]);
						
					}
				}
				
					if($data['hits']==1){
						$this->hits_db = pc_base::load_model('hits_model');
							
						$ids = implode(',', $idss);
						$hitsid = 'c-'.$this->modelid.'-%';
						$sql = "hitsid LIKE '$hitsid'";
				
						
						$order ='hitsid asc ';
						$result = $this->hits_db->select($sql, 'views, hitsid', $data['limit'], $order);
						
						//$result = each($result);
					//	print_r($result);
						if (!empty($result)) {
						foreach ($result as $key=>$val) {
							 $return[$key+1] = array_merge($val, $return[$key+1]);
						}
					}
				}
			}
			
		}
	
//	echo '<pre>';
	
		$cnt = count($return);

		if(STATICS==1){
		
			foreach ($return as $key=>$val){	
				$url = $return[$key]['url'];
				preg_match('/(catid)(.*)/i',$url, $matches);
				//取出 catid=6&id=1
				$cuturl = $matches[2];
				//取出 catid
				preg_match('/(=)([0-9]+)/i',$cuturl, $m);
				//取出id
				preg_match ("/(&id=)+([0-9]{1,5})+/i", $cuturl, $id);
			
				//取出page
				if(preg_match ("/page/i", $cuturl)){
					preg_match('/([0-9]+)/i',$cuturl, $pagenum);
				}
				
				$return[$key]['url'] = SITEURL.'show-'.$m[2].'-'.$id[2].'-'.intval($pagenum[0]).'.html';
			}
		}	
		
		//http://localhost/phpcms/index.php?m=content&c=index&a=show&catid=6&id=1
			
		//	RewriteRule ^show-([0-9]+)-([0-9]+)-([0-9]+).html index.php?m=content&c=index&a=show&catid=$1&id=$2&page=$3
		//print_r($return);
		
		return $return;
	}
	/**
	 * 
	 * 取用内容
	 * @param unknown_type $data
	 */
	function get_content($data){
		$catid = intval($data['catid']);
		if(!$this->set_modelid(18)) return false;
		
		$data_db = $this->db->table_name.'_data';
	
		$page = $_GET['page']?$_GET['page']:1 ;
		if($data['num']){
			$pagesize = $data['num'];
		}else{
			$pagesize = 12;
		}
		//print_r($data);
		$offset = intval($pagesize*($page-1));
		if($data['category']){
			$con = 'a.maxproduct_category = '.$data['category'];
		}elseif ($data['cid']){
			$con = 'a.minproduct_category = '.$data['cid'];
		}
		$con .= ' and b.status =99 ';
		if($data['category']){
			$sql = 'select * from '.$data_db.' as a left join 
			'.$this->db->table_name.' as b on a.id=b.id where '.$con;
			$sql_count = 'select count(b.id) as num from '.$data_db.' as a left join 
			'.$this->db->table_name.' as b on a.id=b.id where '.$con;
		
		}
		else{
			$sql = 'select * from '.$data_db.' as a left join 
			'.$this->db->table_name.' as b on a.id=b.id where b.catid = '.$catid.' and b.status =99  order by a.id desc';
			$sql_count = 'select count(b.id) as num  from '.$data_db.' as a left join 
			'.$this->db->table_name.' as b on a.id=b.id where b.catid = '.$catid.' and b.status =99 ';
		}
		$sql .= " LIMIT $offset,$pagesize";
		
		$this->db->query($sql);
		$return = $this->db->fetch_array();
	
		if($data['hits']==1){
			$this->hits_db = pc_base::load_model('hits_model');
			$ids = array();
			foreach ($return as $v) {
				if (isset($v['id']) && !empty($v['id'])) {
					$hitsid .= 'hitsid = \'c-'.$this->modelid.'-'.$v['id'].'\' or ';
					
				} else {
					continue;
				}
			}
			$sql = substr($hitsid, 0, strlen($hitsid)-3);
	
			$order ='hitsid asc ';
			$result = $this->hits_db->select($sql, 'views, hitsid', $data['limit'], $order);
		
			if (!empty($result)) {
				foreach ($result as $key=>$val) {
					$return[$key] = array_merge($val, $return[$key]);
				}
			}
		}
		
		$this->db->query($sql_count);
		$total = $this->db->fetch_array();
		$total = $total[0]['num'];
	
		$pages = pages($total, $page, $pagesize);
		$return['data'] = $return;
		$return['pages'] = $pages;
		//print_r($return);
		return $return;
		//print_r($datas);exit;
		//echo $this->db->table_name;
		//echo __LINE__;
	}
	
	/**
	 * 相关文章标签
	 * @param $data
	 */
	public function relation($data) {
		$catid = intval($data['catid']);
		if(!$this->set_modelid($catid)) return false;
		$order = $data['order'];
		$sql = "`status`=99";
		$limit = $data['id'] ? $data['limit']+1 : $data['limit'];
		if($data['relation']) {
			$relations = explode('|',$data['relation']);
			$relations = array_diff($relations, array(null));
			$relations = implode(',',$relations);
			$sql = " `id` IN ($relations)";
			$key_array = $this->db->select($sql, '*', $limit, $order,'','id');
		} elseif($data['keywords']) {
			$keywords = str_replace('%', '',$data['keywords']);
			$keywords_arr = explode(' ',$keywords);
			$key_array = array();
			$i =1;
			foreach ($keywords_arr as $_k) {
				$sql2 = $sql." AND `keywords` LIKE '%$_k%'".(isset($data['id']) && intval($data['id']) ? " AND `id` != '".abs(intval($data['id']))."'" : '');
				$r = $this->db->select($sql2, '*', $limit, '','','id');
				$number = count($r);
				if($data['limit']<$number) break;
				foreach ($r as $id=>$v) {
					if($i<= $data['limit'] && !in_array($id, $key_array)) $key_array[$id] = $v;
					$i++;
				}	
			}
		}
		if($data['id']) unset($key_array[$data['id']]);
		return $key_array;
	}
	
	/**
	 * 排行榜标签
	 * @param $data
	 */
	public function hits($data) {
		$catid = intval($data['catid']);
		if(!$this->set_modelid($catid)) return false;

		$this->hits_db = pc_base::load_model('hits_model');
		$sql = $desc = $ids = '';
		$array = $ids_array = array();
		$order = $data['order'];
		$hitsid = 'c-'.$this->modelid.'-%';
		$sql = "hitsid LIKE '$hitsid'";
		if(isset($data['day'])) {
			$updatetime = SYS_TIME-intval($data['day'])*86400;
			$sql .= " AND updatetime>'$updatetime'";
		}
		$hits = array();
		
		$result = $this->hits_db->select($sql, '*', $data['limit'], $order);
		foreach ($result as $r) {
			$pos = strpos($r['hitsid'],'-',2) + 1;
			$ids_array[] = $id = substr($r['hitsid'],$pos);
			$hits[$id] = $r;
		}
		$ids = implode(',', $ids_array);
		if($ids) {
			$sql = "status=99 AND id IN ($ids)";
		} else {
			$sql = '';
		}
		$this->db->table_name = $this->tablename;
		$result = $this->db->select($sql, '*', $data['limit'],'','','id');
		foreach ($ids_array as $id) {
			if($result[$id]['title']!='') {
				$array[$id] = $result[$id];
				$array[$id] = array_merge($array[$id], $hits[$id]);
			}
		}
		return $array;
	}
	/**
	 * 栏目标签
	 * @param $data
	 */
	public function category($data) {
		$data['catid'] = intval($data['catid']);
		$array = array();
		$siteid = $data['siteid'] && intval($data['siteid']) ? intval($data['siteid']) : get_siteid();
		$categorys = getcache('category_content_'.$siteid,'commons');
		$site = siteinfo($siteid);
		$i = 1;
		foreach ($categorys as $catid=>$cat) {
			if($i>$data['limit']) break;
			if((!$cat['ismenu']) || $siteid && $cat['siteid']!=$siteid) continue;
			if (strpos($cat['url'], '://') === false) {
				$cat['url'] = substr($site['domain'],0,-1).$cat['url'];
			}
			if($cat['parentid']==$data['catid']) {
				$array[$catid] = $cat;
				$i++;
			}
		}
		return $array;
	}
	
	/**
	 * 推荐位
	 * @param $data
	 */
	public function position($data) {
		$sql = '';
		$array = array();
		$posid = intval($data['posid']);
		$order = $data['order'];
		$thumb = (empty($data['thumb']) || intval($data['thumb']) == 0) ? 0 : 1;
		$siteid = $GLOBALS['siteid'] ? $GLOBALS['siteid'] : 1;
		$catid = (empty($data['catid']) || $data['catid'] == 0) ? '' : intval($data['catid']);
		if($catid) {
			$siteids = getcache('category_content','commons');
			if(!$siteids[$catid]) return false;
			$siteid = $siteids[$catid];
			$this->category = getcache('category_content_'.$siteid,'commons');
		}
		if($catid && $this->category[$catid]['child']) {
			$catids_str = $this->category[$catid]['arrchildid'];
			$pos = strpos($catids_str,',')+1;
			$catids_str = substr($catids_str, $pos);
			$sql = "`catid` IN ($catids_str) AND ";
		}  elseif($catid && !$this->category[$catid]['child']) {
				$sql = "`catid` = '$catid' AND ";
		}
		if($thumb) $sql .= "`thumb` = '1' AND ";
		$sql .= "`posid` = '$posid' AND `siteid` = '".$siteid."'";
	
		$pos_arr = $this->position->select($sql, '*', $data['limit'],$order);
		if($data['moreinfo']==1){
			$id = $pos_arr[0]['id'];
			$catid = $pos_arr[0]['catid'];
			$content_sql = "";
			
			$siteids = getcache('category_content','commons');
		$siteid = $siteids[$catid];
		$CATEGORYS = getcache('category_content_'.$siteid,'commons');
		
		if(!isset($CATEGORYS[$catid]) || $CATEGORYS[$catid]['type']!=0) showmessage(L('information_does_not_exist'),'blank');
		$this->category = $CAT = $CATEGORYS[$catid];
		$this->category_setting = $CAT['setting'] = string2array($this->category['setting']);
		$siteid = $GLOBALS['siteid'] = $CAT['siteid'];
		
		$MODEL = getcache('model','commons');
		$modelid = $CAT['modelid'];
		
		$tablename = $this->db->table_name = $this->db->db_tablepre.$MODEL[$modelid]['tablename'].'_data';
		$r = $this->db->get_one(array('id'=>$id));
		}
		
		if(!empty($pos_arr)) {
			foreach ($pos_arr as $info) {
				$key = $info['catid'].'-'.$info['id'];
				$array[$key] = string2array($info['data']);
				$array[$key]['url'] = go($info['catid'],$info['id']);
				$array[$key]['id'] = $info['id'];
				$array[$key]['catid'] = $info['catid'];
				if($data['moreinfo']==1){
					$array[$key]['content'] = $r['content'];
				}
			}
		}
		return $array;
	}
	/**
	 * 可视化标签
	 */
	public function pc_tag() {
		$positionlist = getcache('position','commons');
		$sites = pc_base::load_app_class('sites','admin');
		$sitelist = $sites->pc_tag_list();
		
		foreach ($positionlist as $_v) if($_v['siteid'] == get_siteid() || $_v['siteid'] == 0) $poslist[$_v['posid']] = $_v['name'];
		return array(
			'action'=>array('lists'=>L('list','', 'content'),'position'=>L('position','', 'content'), 'category'=>L('subcat', '', 'content'), 'relation'=>L('related_articles', '', 'content'), 'hits'=>L('top', '', 'content')),
			'lists'=>array(
				'catid'=>array('name'=>L('catid', '', 'content'),'htmltype'=>'input_select_category','data'=>array('type'=>0),'validator'=>array('min'=>1)),
				'order'=>array('name'=>L('sort', '', 'content'), 'htmltype'=>'select','data'=>array('id DESC'=>L('id_desc', '', 'content'), 'updatetime DESC'=>L('updatetime_desc', '', 'content'), 'listorder ASC'=>L('listorder_asc', '', 'content'))),
				'thumb'=>array('name'=>L('thumb', '', 'content'), 'htmltype'=>'radio','data'=>array('0'=>L('all_list', '', 'content'), '1'=>L('thumb_list', '', 'content'))),
				'moreinfo'=>array('name'=>L('moreinfo', '', 'content'), 'htmltype'=>'radio', 'data'=>array('1'=>L('yes'), '0'=>L('no')))
			),
			'position'=>array(
				'posid'=>array('name'=>L('posid', '', 'content'),'htmltype'=>'input_select','data'=>$poslist,'validator'=>array('min'=>1)),
				'catid'=>array('name'=>L('catid', '', 'content'),'htmltype'=>'input_select_category','data'=>array('type'=>0),'validator'=>array('min'=>0)),
				'thumb'=>array('name'=>L('thumb', '', 'content'), 'htmltype'=>'radio','data'=>array('0'=>L('all_list', '', 'content'), '1'=>L('thumb_list', '', 'content'))),			
				'order'=>array('name'=>L('sort', '', 'content'), 'htmltype'=>'select','data'=>array('listorder DESC'=>L('listorder_desc', '', 'content'),'listorder ASC'=>L('listorder_asc', '', 'content'),'id DESC'=>L('id_desc', '', 'content'))),
			),
			'category'=>array(
				'siteid'=>array('name'=>L('siteid'), 'htmltype'=>'input_select', 'data'=>$sitelist),
				'catid'=>array('name'=>L('catid', '', 'content'), 'htmltype'=>'input_select_category', 'data'=>array('type'=>0))
			),
			'relation'=>array(
				'catid'=>array('name'=>L('catid', '', 'content'), 'htmltype'=>'input_select_category', 'data'=>array('type'=>0), 'validator'=>array('min'=>1)),
				'order'=>array('name'=>L('sort', '', 'content'), 'htmltype'=>'select','data'=>array('id DESC'=>L('id_desc', '', 'content'), 'updatetime DESC'=>L('updatetime_desc', '', 'content'), 'listorder ASC'=>L('listorder_asc', '', 'content'))),
				'relation'=>array('name'=>L('relevant_articles_id', '', 'content'), 'htmltype'=>'input'),
				'keywords'=>array('name'=>L('key_word', '', 'content'), 'htmltype'=>'input')
			),
			'hits'=>array(
				'catid'=>array('name'=>L('catid', '', 'content'), 'htmltype'=>'input_select_category', 'data'=>array('type'=>0), 'validator'=>array('min'=>1)),
				'day'=>array('name'=>L('day_select', '', 'content'), 'htmltype'=>'input', 'data'=>array('type'=>0)),
			),
				
		);
	}
	/**
	 * 
	 * 取得最新9个公司会员
	 * @param unknown_type $data
	 */
	function list_company($data){
		$this->company_db = pc_base::load_model('company_model');
		$c_data = $this->company_db->select('','*',9, 'companyid desc');
		return $c_data;
		
	}
	/**
	 * 
	 * 取得所有个公司会员
	 * @param unknown_type $data
	 */
	function list_company_all($data){
		$this->company_db = pc_base::load_model('company_model');
		if($_GET['name']){
			$name = '  companyname like \'%'.$_GET['name'].'%\'';
		}else{$name=' 1=1 ';}
		if($_GET['areaid']){
			$city = ' and area ='.$_GET['areaid'].' ';
		}else{$city=' and 1=1';}
		if($_GET['price_start']){
			$price_start = ' and price_start > '.$_GET['price_start'].' ';
		}else{$city=' and 1=1';}
		if($_GET['price_end']){
			$price_end = ' and price_end < '.$_GET['price_end'].' ';
		}else{$price_end=' and 1=1';}
		$sql = $name.$city.$price_start.$price_end.' and city='.$data['cityid'];
	
		$page = $_GET['page'] ? $_GET['page']:1;
		$pagesize=12;
		$offset = intval($pagesize*($page-1));
		$return = $this->company_db->list_company($sql, $offset, $pagesize);
		$pages = pages($return['total'], $page, $pagesize);
		$return['data'] = $return['data'];
		$return['pages'] = $pages;
		return $return;
		
	}
	
	function list_designer($data){
		
		$this->designer_db = pc_base::load_model('designer_model');
		if($_GET['name']){
			$name = '  name like \'%'.$_GET['name'].'%\'';
		}else{$name=' 1=1 ';}
		if($_GET['areaid']){
			$city = ' and area ='.$_GET['areaid'].' ';
		}else{$city=' and 1=1';}
		
		
		$sql = $name.$city.' and city='.$data['cityid'];
		$page = $_GET['page'] ? $_GET['page']:1;
		$pagesize=12;
		$offset = intval($pagesize*($page-1));
		$return = $this->designer_db->list_designers($sql, $offset, $pagesize);
		$pages = pages($return['total'], $page, $pagesize);
		$return['data'] = $return['data'];
		$return['pages'] = $pages;
		return $return;
		
	}
	function get_city($data){
	//pc_base::load_sys_class('param');
		$cityid = CITYID;
		//echo __LINE__;
		//echo $cityid;exit;
		//pc_base::load_sys_class('param');
		
		//$cityid = param::get_cookie('_cityid');
		//$cityid = param::get_cookie('cityid');
	
		
	 	//$cityid = 	$_SESSION['cityid'];
	 		$cities = getcache('3360', 'linkage');
	 	
		$data = $cities['data'];
		$id = $cityid;
		$l = $data;
	
		if($id!=0){
			if(is_array($data))
			{
				if($data[$k]['linkageid']==$id){
						$letter = $data[$k]['description'];
					}
					
				foreach ($data as $k=>$v){
				
					if($v['parentid']!= $id || $v['parentid']==0){
						unset($data[$k]);
					}
					
				}	
				foreach ($data as $key=>$val){
					$area[$key]['name'] = $val['name'];
					$area[$key]['linkageid'] = $val['linkageid'];
				//	print_r($area);exit;
				}
			}	
		}
		else
		{
			$area[$key]['name'] = '';
			$area[$key]['linkageid'] = '';
		}
		return $area;
	}
	public function getcity(){
		$cities = getcache('3360', 'linkage');
		$data = $cities['data'];
		if(is_array($data)){
			foreach ($data as $k=>$v){
				if($v['description']==''){
					unset($data[$k]);
				}
			}
		}	
		$city = $data;
		return $city;
	}
	/**
	 * 
	 * 取建材产品的的分类
	 */
	function get_product_cat($param){
		$cat = getcache('3410', 'linkage');
		$id = $param['id'];
		$cats = $cat['data'];
		if($id>0){
			foreach ($cats as $k=>$v)
			{	
				if($v['parentid']!= $id){	
					unset($cats[$k]);
				}else{}	
			}		
			return $cats;
		}
		$data = $cat['data'];
		return $data;
	}
	function get_prodcut_category(){
		$cities = getcache('3410', 'linkage');
		$data = $cities['data'];
		$id = $_POST['id'];
		$l = $data;
		if($id!=0){
			if(is_array($data))
			{
				if($data[$k]['linkageid']==$id){
						$letter = $data[$k]['description'];
					}
					echo $data[$k]['linkageid'];
				foreach ($data as $k=>$v){
				
					if($v['parentid']!= $id || $v['parentid']==0){
						unset($data[$k]);
					}
					
				}	
				$str .= '<option disabled style="background-color: rgb(238, 238, 238); color: rgb(255, 0, 0); font-weight: bold;">请先选择产品小类</option>';
				foreach ($data as $key=>$val){
					
					$str .= '<option value="'.$val['linkageid'].'">'.$val['name'].'</option>';
				}
			}	
		}
		else
		{
			$str .= '<option disabled style="background-color: rgb(238, 238, 238); color: rgb(255, 0, 0); font-weight: bold;">请先选择产品小类</option>';	
		}
		
		$data = array();
		$arr = array('str'=>$str,'letter'=>$l[$id]['description']);
		//print_r($arr);
		echo json_encode($arr);
	}
	/**
	 * 
	 * 取装修空间分类
	 */
	function get_decoration_space($param){
		$cat = getcache('3377', 'linkage');
		$data = $cat['data'];
			foreach ($data as $k=>$v)
			{	
				if($v['parentid']!= 0){	
					unset($data[$k]);
				}else{}	
			}	
			return $data;
	}
	/**
	 * 
	 * 取得虚拟家装各种分类
	 */
	function get_xn_cat($param){

		$cat = getcache(3433, 'linkage');
		$data = $cat['data'];
	
			foreach ($data as $k=>$v)
			{	
				if($v['parentid']!= $param['id']){	
					unset($data[$k]);
				}else{}	
			}	
			return $data;
	}
	/**
	 * 
	 * 取户型分类
	 */
	function get_house_style($param){
		$cat = getcache('3377', 'linkage');
		$data = $cat['data'];
			foreach ($data as $k=>$v)
			{	
				if($v['parentid']== 0){	
					unset($data[$k]);
				}else{}	
			}	
			return $data;
	}

 	/* 
	 * 取风格分类分类
	 */
	function get_decoration_style($param){
		$cat = getcache('3379', 'linkage');
		$data = $cat['data'];
		return $data;
	}
	//取得公司资历
	function get_qualification(){
		$cat = getcache('3451', 'linkage');
		$data = $cat['data'];
		return $data;
	}
	/**
	 * 
	 * 求购列表
	 * @param unknown_type $data
	 */
	function get_buy_prodcut_info($data){
		if(isset($data['where'])) {
			$sql = $data['where'];
		} else {
			$thumb = intval($data['thumb']) ? " AND thumb != ''" : '';
			if($this->category[$catid]['child']) {
				$catids_str = $this->category[$catid]['arrchildid'];
				$pos = strpos($catids_str,',')+1;
				$catids_str = substr($catids_str, $pos);
				//$sql = "status=99 AND catid IN ($catids_str)".$thumb;
			} else {
				//$sql = "status=99 AND catid='$catid'".$thumb;
			}
		}
		$order = $data['order'];
		
		$this->buy_product_db = pc_base::load_model('buy_product_model');
		//$return = $this->buy_product_db->select('', '*', $data['limit'], $order, '', 'buyid');
		$page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
		$return = $this->buy_product_db->listinfo('',$order = 'buyid DESC',$page, $pages = '2');
		$pages = $this->buy_product_db->pages;
		
		//	echo '<pre>';
		//print_r($return);		
		$data['moreinfo'] = 1; //这句自已加的
		
		
		$cnt = count($return);


		if(STATICS==1){
		
			foreach ($return as $key=>$val){	
				$url = $return[$key]['url'];
				preg_match('/(catid)(.*)/i',$url, $matches);
				//取出 catid=6&id=1
				$cuturl = $matches[2];
				//取出 catid
				preg_match('/(=)([0-9]+)/i',$cuturl, $m);
				//取出id
				preg_match ("/(&id=)+([0-9]{1,5})+/i", $cuturl, $id);
			
				//取出page
				if(preg_match ("/page/i", $cuturl)){
					preg_match('/([0-9]+)/i',$cuturl, $pagenum);
				}
				
				$return[$key]['url'] = APP_PATH.'show-'.$m[2].'-'.$id[2].'-'.intval($pagenum[0]).'.html';
			}
		}	
		
		
		$returns['data'] = $return;
		$returns['page']['nav']=$pages;
		return $returns;
	}
	function get_business(){
		$this->dbs = pc_base::load_model('content_model');
		$id = intval($_GET['id']);
		$datas = $this->dbs->get_businessby_productid($id);
		$datas = $datas[0];
		return $datas;
	}
	//投标公司列表
	function list_zhaobiao_reply($data){
		$this->zhaobiao_reply_db = pc_base::load_model('zhaobiao_reply_model');
	
		$page = $_GET['page']?$_GET['page']:1 ;
		$pagesize = 15;
		$offset = intval($pagesize*($page-1));
		$username = $data['username'];
		
		$reply_data = $this->zhaobiao_reply_db->get_list($username, $offset, $pagesize);
		$total = $this->zhaobiao_reply_db->get_list_count($username);
		
		$total = $total[0]['cnt'];
	
		$pages2 = pages($total, $page, $pagesize);

		$returns['data'] = $reply_data;
		$returns['page']['nav']=$pages2;
		return $returns;
	}
	function get_messages($data){
		$this->meesages_db = pc_base::load_model('messages_model');
	
		$page = $_GET['page']?$_GET['page']:1 ;
		$pagesize = 15;
		$offset = intval($pagesize*($page-1));
		$username = $data['username'];
		$this->member_db = pc_base::load_model('member_model');
		
		$user = $this->member_db->get_one(array('username'=>$username));
		
		$message_data = $this->meesages_db->get_list($username, $offset, $pagesize);
		
		$total = $this->meesages_db->get_list_count($username);
		//print_r($message_data);
		$total = $total[0]['cnt'];
	
		$pages2 = pages($total, $page, $pagesize);

		$returns['data'] = $message_data;
		$returns['page']['nav']=$pages2;
		return $returns;
	}
	//求购回复列表
	function list_buy_product_reply($data){
		$this->buy_product_reply_db = pc_base::load_model('buy_product_reply_model');
	
		$page = $_GET['page']?$_GET['page']:1 ;
		$pagesize = 15;
		$offset = intval($pagesize*($page-1));
		$id = $data['id'];
		
		$reply_data = $this->buy_product_reply_db->get_list($id, $offset, $pagesize);
		$total = $this->buy_product_reply_db->get_list_count($id);
		
		$total = $total[0]['cnt'];
	
		$pages2 = pages($total, $page, $pagesize);

		$returns['data'] = $reply_data;
		$returns['page']['nav']=$pages2;
		return $returns;
	}

}